package com.zz.common.utils;

import com.zz.common.config.Constants;

import java.nio.charset.StandardCharsets;

public class StringUtil {

    public static String getString(byte[] data) {
        if (null == data) {
            return Constants.Strings.EMPTY_STR;
        }
        return new String(data, StandardCharsets.UTF_8);
    }


    public static boolean hasText(String str) {
        try {
            return str != null && !str.isEmpty() && containsText(str);
        } catch (Exception e) {
            return false;
        }
    }

    private static boolean containsText(CharSequence str) {
        int strLen = str.length();

        for (int i = 0; i < strLen; ++i) {
            if (!Character.isWhitespace(str.charAt(i))) {
                return true;
            }
        }
        return false;
    }
}
